package io.renren.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.dao.ArticleDao;
import io.renren.dto.ArticleListDto;
import io.renren.entity.Article;
import io.renren.service.ArticleService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("articleService")
public class ArticleServiceImpl extends ServiceImpl<ArticleDao, Article> implements ArticleService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<Article> page = this.selectPage(
                new Query<Article>(params).getPage(),
                new EntityWrapper<>()
        );

        return new PageUtils(page);
    }

    @Override
    public Page<ArticleListDto> queryArticlePage( Integer page, Integer limit ) {
        Page<ArticleListDto> data = new Page<>( page, limit );
        baseMapper.queryArticleList( data );
        return data;
    }

    @Override
    public Article queryDetail(Integer articleId) {
        Article article = this.selectById( articleId );
        if( article == null ){
            return null;
        }
        article.setArticleData( baseMapper.queryData( articleId )  );
        return  article;
    }
}
